/**
 * Project Wonderland
 *
 * Copyright (c) 2004-2010, Sun Microsystems, Inc., All Rights Reserved
 *
 * Redistributions in source code form must reproduce the above copyright and
 * this condition.
 *
 * The contents of this file are subject to the GNU General Public License,
 * Version 2 (the "License"); you may not use this file except in compliance
 * with the License. A copy of the License is available at
 * http://www.opensource.org/licenses/gpl-license.php.
 *
 * Sun designates this particular file as subject to the "Classpath" exception
 * as provided by Sun in the License file that accompanied this code.
 */
package org.jdesktop.wonderland.modules.season.client;

import java.util.Observable;
import java.util.Observer;
import org.jdesktop.wonderland.client.cell.Cell;
import org.jdesktop.wonderland.client.cell.CellComponent;
import org.jdesktop.wonderland.client.cell.ChannelComponent;
import org.jdesktop.wonderland.common.cell.messages.CellMessage;
import org.jdesktop.wonderland.common.cell.state.CellComponentClientState;
import org.jdesktop.wonderland.modules.season.common.SeasonCellChangeMessage;
import org.jdesktop.wonderland.modules.season.common.SeasonCellComponentClientState;
import org.jdesktop.wonderland.modules.season.common.SeasonCellEnum;

/**
 * Client-side season Cell Component.
 *
 * @author christian
 */
public class SeasonCellComponent extends CellComponent{

    private SeasonCellEnum season;
    private Cell uperCell;

    /**
     * Constructor, takes the Cell associated with the Cell Component.
     *
     * @param cell The Cell associated with this component
     */
    public SeasonCellComponent(Cell cell) {
        super(cell);
        uperCell = cell;
        
    }
    
    @Override
    public void setClientState(CellComponentClientState clientState) {
        super.setClientState(clientState);
        season = ((SeasonCellComponentClientState) clientState).getSeason();

        System.out.println("CLIENT SEASON Season: " + season);
    }

    public SeasonCellEnum getSeason() {
        return season;
    }

    class ShapeCellMessageReceiver implements ChannelComponent.ComponentMessageReceiver {

        public void messageReceived(CellMessage message) {
            SeasonCellChangeMessage sccm = (SeasonCellChangeMessage) message;
            if (!sccm.getSenderID().equals(uperCell.getCellCache().getSession().getID())) {
                season = sccm.getSeason();
            }
        }
    }
}